package com.lvmama.pangolin.hbaseutil;


import java.io.IOException;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.lvmama.pangolin.conf.HbaseRedisSettings;

@Configuration
//TODO PropertiesConfig先装配
@EnableConfigurationProperties(HbaseRedisSettings.class)
public class HbaseConfiguration {
	/**  
	* @Title：HbaseConfiguration.java
	* @Author:zhoutianqi
	* @Description:
	* @Date：2017年2月10日上午10:23:18  
	*/
	@Autowired
	private HbaseRedisSettings hbaseRedisSettings;
	
	@Bean
	public org.apache.hadoop.conf.Configuration configurationBean(){
		//System.setProperty("hadoop.home.dir", "C:\\Users\\Administrator\\Desktop\\hadoop-2.7.3\\hadoop-2.7.3");
		if(!hbaseRedisSettings.getHbaseEnable().equals("true")){return null;}
		org.apache.hadoop.conf.Configuration configuration = HBaseConfiguration.create();
		configuration.set("hbase.rootdir", hbaseRedisSettings.getHbasemaster());
		configuration.set("hbase.zookeeper.property.dataDir", hbaseRedisSettings.getHbasezookeeperpropertydataDir()); 
        configuration.set("hbase.zookeeper.quorum", hbaseRedisSettings.getHbasezookeeperquorum());
        configuration.set("hbase.cluster.distributed", hbaseRedisSettings.getHbaseclusterdistributed());
        System.out.println("HbaseConfiguration configuration数据："+configuration.toString());
        return configuration;
	}
	@Bean
	public Connection connectionBean(){
		//System.setProperty("hadoop.home.dir", "C:\\Users\\Administrator\\Desktop\\hadoop-2.7.3\\hadoop-2.7.3");
		if(!hbaseRedisSettings.getHbaseEnable().equals("true")){return null;}
		Connection connection = null;
		try {
			connection = ConnectionFactory.createConnection(configurationBean());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("HbaseConfiguration connection数据："+connection.toString());
		return connection;
	}
	
}
